package fanfou4j.type;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import fanfou4j.org.json.JSONArray;
import fanfou4j.org.json.JSONObject;
import fanfou4j.util.DateUtil;

public class Status implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6406214930348658839L;
	private Date created_at;
	private String id;
	private String text;
	private String source;
	private boolean truncated;
	private String in_reply_to_status_id;
	private String in_reply_to_user_id;
	private boolean favorited;
	private String in_reply_to_screen_name;
	private User user;
	private Photo photo;

	public Status(JSONObject json) throws Exception {
		init(json);
	}

	private void init(JSONObject json) throws Exception {
		if (json != null) {
			created_at=DateUtil.parseDate(json.getString("created_at"), "EEE MMM dd HH:mm:ss ZZZZZ yyyy");;
			id=json.getString("id");
			text=json.getString("text");
			source=json.getString("source");
			truncated=json.getBoolean("truncated");
			in_reply_to_status_id=json.getString("in_reply_to_status_id");
			in_reply_to_user_id=json.getString("in_reply_to_user_id");
			favorited=json.getBoolean("favorited");
			in_reply_to_screen_name=json.getString("in_reply_to_screen_name");
			if(!json.isNull("user")){
				user=new User(json.getJSONObject("user"));								
			}
			if(!json.isNull("photo")){
				photo=new Photo(json.getJSONObject("photo"));
			}			
		}

	}
	public static List<Status> getStatusList(JSONArray array) throws Exception{
		int size=array.length();
		List<Status> list=new ArrayList<Status>();
		for (int i = 0; i < size; i++) {
			list.add(new Status(array.getJSONObject(i)));
		}
		return list;
	}

	public Date getCreated_at() {
		return created_at;
	}

	public String getId() {
		return id;
	}

	public String getText() {
		return text;
	}

	public String getSource() {
		return source;
	}

	public boolean isTruncated() {
		return truncated;
	}

	public String getIn_reply_to_status_id() {
		return in_reply_to_status_id;
	}

	public String getIn_reply_to_user_id() {
		return in_reply_to_user_id;
	}

	public boolean isFavorited() {
		return favorited;
	}

	public String getIn_reply_to_screen_name() {
		return in_reply_to_screen_name;
	}

	public User getUser() {
		return user;
	}

	public Photo getPhoto() {
		return photo;
	}

	@Override
	public String toString() {
		return "Status [created_at=" + created_at + ", id=" + id + ", text="
				+ text + ", source=" + source + ", truncated=" + truncated
				+ ", in_reply_to_status_id=" + in_reply_to_status_id
				+ ", in_reply_to_user_id=" + in_reply_to_user_id
				+ ", favorited=" + favorited + ", in_reply_to_screen_name="
				+ in_reply_to_screen_name + ", user=" + user + ", photo="
				+ photo + "]";
	}
	

}
